package qb.spring.springBean.service;
import org.springframework.*;
import qb.spring.springBean.domain.student;
import qb.spring.springBean.domain.Score;

@Controller
@RequestMapping("qb/test") //请求的路径
public class Controller {

    @RequestMapping(value="/Score/{name}", method = RequestMethod.GET)
    public @ResponseBody Score getCoffeeInXML(@PathVariable String name) {
        Score score = new Score(299,99,100,89,92);
        return score;
    }
    /**
     * 直接返回字符串
     * @param teamname
     * @param request
     * @return
     */
    //请求的路径，方式
    @RequestMapping(value = "v1.0/new/{teamname}", method = RequestMethod.GET)
    @ResponseBody public String foo4(@PathVariable String teamname, HttpServletRequest request) {
        //可以使用teamname获取url路径分隔
        //获取请求的参数
        String name = request.getParameter("name");
        String totalScore = request.getParameter("totalScore");
        String contacts = request.getParameter("contacts");
        String contactPhone = request.getParameter("contactPhone");
        student student = new student(name, totalScore,contacts,contactPhone);
        return student.toString();
    }
    /**
     * 直接返回对象，自动转化为JSON格式
     * @param teamname
     * @param request
     * @return
     */
    @RequestMapping(value = "v2.0/new/{teamname}", method = RequestMethod.GET)
    @ResponseBody public Student foo5(@PathVariable String teamname, HttpServletRequest request) {
        //可以使用teamname获取url路径分隔
        //获取请求的参数
        String name = request.getParameter("name");
        String age = request.getParameter("age");
        Student student = new Student(name, age);
        return student;
    }





}